//
//  ListMaintenaceTypeViewController.m
//  FMS
//
//  Created by Steven on 10/12/13.
//  Copyright (c) 2013 QGSVN. All rights reserved.
//

#import "ListMaintenaceTypeViewController.h"

@interface ListMaintenaceTypeViewController ()

@end


@implementation ListMaintenaceTypeViewController
@synthesize delegate;
- (id)initWithStyle:(UITableViewStyle)style typeCategory:(int)typeFilter
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
        dictLanguage = [ApplicationDelegate.arrayLanguage objectAtIndex:0];
        typeCategory = typeFilter;
    }
    return self;
}
// list category by type
- (void)listCategorySchedule{
    [scheduleCategorys removeAllObjects];
    if (typeCategory == Category_Schedule_Tag) {
        NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@",[dictLanguage objectForKey:@"schedule.title-all"]],@"scheduleCategory",[NSNumber numberWithInteger:0],@"CategoryType", nil];
        [scheduleCategorys addObject:dict];
        for (int i = 1; i < 10; i++) {
            NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Maintenace %d",i],@"scheduleCategory",[NSNumber numberWithInteger:i],@"CategoryType", nil];
            [scheduleCategorys addObject:dict];
        }
    }
    else{
        
        NSMutableDictionary *dict;
        dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@",[dictLanguage objectForKey:@"schedule.title-select-category-program"]],@"scheduleCategory",[NSNumber numberWithInteger:0],@"CategoryType", nil];
        [scheduleCategorys addObject:dict];
        dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Maintenace"],@"scheduleCategory",[NSNumber numberWithInteger:1],@"CategoryType", nil];
        [scheduleCategorys addObject:dict];
        dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Inspection"],@"scheduleCategory",[NSNumber numberWithInteger:2],@"CategoryType", nil];
        [scheduleCategorys addObject:dict];
    }
    [self.tableView reloadData];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    scheduleCategorys = [[NSMutableArray alloc] init];
    [self listCategorySchedule];
    
    [self setContentSizeForViewInPopover:CGSizeMake(320, 400)];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [scheduleCategorys count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
    }
    if (indexPath.row == 0 && typeCategory != Category_Schedule_Tag) {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    else
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
    // Configure the cell...
    NSMutableDictionary *dict = [scheduleCategorys objectAtIndex:indexPath.row];
    cell.textLabel.text = [dict objectForKey:@"scheduleCategory"];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0 && typeCategory != Category_Schedule_Tag)
        return;
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSMutableDictionary *dict = [scheduleCategorys objectAtIndex:indexPath.row];
    if ([delegate respondsToSelector:@selector(didSelectCategoryMaintenance:)]) {
        [delegate didSelectCategoryMaintenance:dict];
    }
}
@end
